// components/search/search.js
const componentBehavior = require('../../js/common/ComponentBehavior')

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    name: {
      type: String,
      value: ""
    },
    placeholder: {
      type: String,
      value: ""
    },
    keywords: {
      type: String,
      value: ""
    },
    isSingle: {
      type: Boolean,
      value: false
    },
    isSkip: {
      type: Boolean,
      value: false
    },
    scan: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    keywords: ""
  },

  behaviors: [componentBehavior],
  /**
   * 组件的方法列表
   */
  methods: {
    keywordInput: function (e) {
      // this.data.keywords = e.detail.value;
      var that = this;
      this.setData({
        keywords: e.detail.value
      })
      that.triggerEvent("onSearch", e.detail.value);
      // if(that.data.isSkip){
      //   setTimeout(function(){
      //     that.bindSearch();
      //   },2000)
      // }
    },
    bindSearch: function (e) {
      this.triggerEvent("bindSearch", this.data.keywords);
    },
    bindScan() {
      this.triggerEvent("bindScan")
    },
    focus(e) {
      this.triggerEvent('focus', {
        event: e
      })
    },
    /**
     * 点击输入
     */
    tapInput() {
      this.setData({
        activeInput: true
      })
    },
    /**
     * 失去焦点
     */
    blur() {
      this.setData({
        activeInput: false
      })
    },
    delete() {
      this.setData({
        keywords: ''
      })
    },
  }
})